home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / docs / linux-do / programm / lpg-0.4 / lpg-0 / LPG / examples / splay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-10  |  1.6 KB  |  72 lines

  1. /*
  2.  *  AUTHOR: Sven Goldt (goldt@math.tu-berlin.de)
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of the GNU General Public License
  6.  *  as published by the Free Software Foundation; either version 2
  7.  *  of the License, or (at your option) any later version.
  8.  *
  9.  *  This program is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14. */
  15.  
  16.  
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <stdlib.h>
  20. #include <sys/types.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23. #include <fcntl.h>
  24. #include <sys/kd.h>
  25. #include <sys/ioctl.h>
  26.  
  27. extern float name_to_val(char *tune);
  28.  
  29. main(int argc, char **argv)
  30. {
  31. int fd=1,tone,duration;
  32. float frequency;
  33. char sounddata[20];
  34.  
  35.  if (argc>1)
  36.  {
  37.   fprintf(stderr,"I need sounddatas from stdin !\n");
  38.   exit(-1);
  39.  }
  40.  
  41.  if (strncmp(getenv("TERM"), "xterm", 5) == 0)
  42.  {
  43.   fd = open("/dev/console", O_WRONLY);
  44.   if (fd < 0) fd = 1; /* stdout */
  45.  }
  46.  
  47.  while (fgets(sounddata,20,stdin)!=NULL)
  48.  {
  49.  
  50.   if (isalpha(*sounddata))
  51.   {
  52.    strtok(sounddata,"\t, "); /* delimiters for frequency and length */
  53.    frequency=name_to_val(sounddata);
  54.    sscanf(strtok(NULL,"\r"),"%d",&duration);
  55.   }
  56.   else sscanf(sounddata,"%f%*c%d",&frequency,&duration);
  57.  
  58.   if (frequency!=0.0) tone=1190000/frequency;/*calculate value for pc speaker*/
  59.   else tone=0;
  60.   ioctl(fd,KIOCSOUND,tone); 
  61.   usleep(duration*1000); /* duration in ms */
  62.  
  63.  }
  64.  ioctl(fd,KIOCSOUND,0); /* sound off */
  65.   
  66.  if (fd>2) close(fd); /* console */
  67.  
  68.  exit(0);
  69. }
  70.  
  71.  
  72.